Fundamental types
From Cppreference
See this for the types supplied by the standard C++ library.
Contents |
[edit] Boolean type
- bool - type, capable of holding one of the two values: true or false.
[edit] Character types
- signed char - type for signed character representation.
- unsigned char - type for unsigned character representation.
- char - type for character representation which can be most efficiently processed on the target system (equivalent to either signed char or unsigned char).
- wchar_t - type for wide character representation
- char16_t - type for UTF-16 character representation (C++11 feature)
- char32_t - type for UTF-32 character representation (C++11 feature)
[edit] Integer types
- int - basic integer type. Can be omitted if any of the modifiers are present. If no length modifiers are present, guaranteed to have width of at least 16 bits. However, on 32/64 bit systems it is almost exclusively guaranteed to have width of at least 32 bits (see below).
[edit] Modifiers
Modifies the integer type. Can be mixed in any order. Only one of each group can be present in type definition.
Signedness
- signed - target type will have signed representation (this is the default if omitted)
- unsigned - target type will have unsigned representation
Size
- short - target type will be optimized for space and will have width of at least 16 bits.
- long - target type will have width of at least 32 bits.
- long long - target type will have width of at least 64 bits (C++11 feature)
[edit] Properties
The following table summarizes all available integer types and their properties:
| Type specifier | Equivalent type | Width in bits by data model | ||||
|---|---|---|---|---|---|---|
| C++ standard | LP32 | ILP32 | LLP64 | LP64 | ||
| short
| short int | at least 16 | 16 | 16 | 16 | 16 |
| short int
| ||||||
| signed short
| ||||||
| signed short int
| ||||||
| unsigned short
| unsigned short int | |||||
| unsigned short int
| ||||||
| int
| int | at least 16 | 16 | 32 | 32 | 32 |
| signed
| ||||||
| signed int
| ||||||
| unsigned
| unsigned int | |||||
| unsigned int
| ||||||
| long
| long int | at least 32 | 32 | 32 | 32 | 64 |
| long int
| ||||||
| signed long
| ||||||
| signed long int
| ||||||
| unsigned long
| unsigned long int | |||||
| unsigned long int
| ||||||
| long long
| long long int (C++11) | at least 64 | 64 | 64 | 64 | 64 |
| long long int
| ||||||
| signed long long
| ||||||
| signed long long int
| ||||||
| unsigned long long
| unsigned long long int (C++11) | |||||
| unsigned long long int
| ||||||
[edit] Data models
32 bit systems:
- LP32:
- Win16 API
- ILP32;
- Win32 API
- Unix and Unix-like systems (Linux, MacOSX)
64 bit systems:
- LLP64
- Win64 API
- LP64
- Unix and Unix-like systems (Linux, MacOSX)
[edit] Floating point types
- float - single precision floating point type. Usually IEEE-754 32 bit floating point type
- double - double precision floating point type. Usually IEEE-754 64 bit floating point type
- long double - extended precision floating point type. Does not necessarily map to types mandated by IEEE-754. Usually 80-bit x87 floating point type on x86 and x86-64 architectures.
[edit] Range of values
Note: C++ standard sets minimum requirements on value ranges of arithmetic types, implementations may exceed them (see data models above) as long as the relationship holds: 1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long). In particular, virtually every implementation's minimum value is at least one less than the Standard's requirement.
| Type | Size in bits | Value range | |
|---|---|---|---|
| Approximate | Exact | ||
| character | 8 (signed) | -127 to 127 | |
| 8 (unsigned) | 0 to 255 | ||
| integral | 16 (signed) | ± 3.3 · 104 | -32767 to 32767 |
| 16 (unsigned) | 0 to 6.6 · 104 | 0 to 65535 | |
| 32 (signed) | ± 2.2 · 109 | -2,147,483,647 to 2,147,483,647 | |
| 32 (unsigned) | 0 to 4.3 · 109 | 0 to 4,294,967,295 | |
| 64 (signed) | ± 9.2 · 1018 | -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807 | |
| 64 (unsigned) | 0 to 1.8 · 1019 | 0 to 18,446,744,073,709,551,615 | |
| floating point | 32 (IEEE-754) | ± 3.4 · 10± 38 (~7 digits) | -- |
| 64 (IEEE-754) | ± 1.7 · 10± 308 (~15 digits) | -- | |
[edit] Keywords
bool, true, false, char, wchar_t, char16_t, char32_t, int, short, long, signed, unsigned, float, double